<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>es6的解构赋值</title>
</head>
<body>
    <script>
        // 数组解构赋值
        let arr = [1, 2, 3, 4, 5];
        let [a, b] = arr;
        console.log(a); // 1
        console.log(b); // 2

        // // 对象解构赋值
        let obj = { x: 1, y: 2 };
        let { y, x } = obj;
        console.log(x); // 1
        console.log(y); // 2

        // // 嵌套解构赋值
        let nestedArr = [1, [2, 3], 4];
        let [first, [second, third]] = nestedArr;
        console.log(first); // 1
        console.log(second); // 2
        console.log(third); // 3

        let nestedObj = { a: { b: 1 }, c: 2 };
        let { a: { b:p }, c } = nestedObj;
        console.log(p); // 1
        console.log(c); // 2
    </script>
</body>
</html>